<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
  	<meta charset="utf-8">
	<meta name="renderer" content="webkit">
 	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
 	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  	<title>${SYSTEM_NAME}</title>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/static/layuiadmin/layui/css/layui.css?v=${FILE_VERSION}" media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/static/layuiadmin/style/admin.css?v=${FILE_VERSION}" media="all">
  	<link rel="stylesheet" href="${pageContext.request.contextPath}/static/js/zTree_v3/css/metroStyle/metroStyle.css?v=${FILE_VERSION}" type="text/css">
</head>
<body>
<div style="border: 1px solid #ccc;" >
	<input id="queryTop" value="false" type="hidden">
	<input id="isFirst" value="false" type="hidden">
	<input id="isOrgFirst" value="true" type="hidden">
	<input id="isSelectFather" value="${isSelectFather }" type="hidden">
	<input id="isShowBranch" value="true" type="hidden" placeholder="isShowBranch">
	<input id="selType" value="${selType}" type="hidden" placeholder="selType">
	<input id="showType" value="${showType }" type="hidden" placeholder="showType">
 	<ul id="treeRegion" class="ztree"></ul>
 </div>

<script src="${pageContext.request.contextPath}/static/js/common-2.0.0.js?v=${FILE_VERSION}"></script>
<script src="${pageContext.request.contextPath}/static/layuiadmin/layui/layui.js?v=${FILE_VERSION}"></script>
<script src="${pageContext.request.contextPath}/static/js/jquery-3.3.1.min.js?v=${FILE_VERSION}"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/zTree_v3/js/jquery.ztree.core.js?v=${FILE_VERSION}"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/zTree_v3/js/jquery.ztree.excheck.js?v=${FILE_VERSION}"></script>
<script>
	var isSelectFather = $("#isSelectFather").val();
var ZtreeObj;

var updateTableCell;
var selType = $("#selType").val();
var setting = {
	data: {
		simpleData: {
			enable: true
		}
	},
	edit: {
		enable: false
	},
	async: {
		enable: true,
		url: getUrl
	},
	callback : {
		onClick: treeOnClick,
		beforeClick : function(treeId, treeNode, clickFlag){
			if(isSelectFather == "false"){
				// 默认只能选择党支部
				var type = '3';
				var msg = "只能选择支部";
				if(selType == 1){
					type = '1';
					var msg = "只能选择党委";
				}else if(selType == 4){
					type = '4';
					var msg = "只能选择党小组";
				}
				if (treeNode.type== type) {
					return true;
				}else{
					layer.msg(msg);
					return false;
				}
			}
		}
	}
};

function getUrl(treeId, treeNode) {
	var queryTop = $("#queryTop").val();
	return getContextPath() + '/sys/org/list/getByParentId?parentId=' + treeNode.id+"&showType="+selType
			+ "&queryTop=" + queryTop;

}


function treeOnClick(event, treeId, treeNode) {
	parentName = treeNode.name;
	var selType = $("#selType").val();
	if(selType == 1){
		parent.setParty(treeNode.id, treeNode.name, treeNode.type);
	}else if(selType == 4){
		parent.setTeam(treeNode.id, treeNode.name, treeNode.pId);
	}else{
		parent.setOrg(treeNode.id, treeNode.name, treeNode.type);
	}
	closed();
}

$(document).ready(function(){


	var queryTop = $("#queryTop").val();
	var isFirst = $("#isFirst").val();
	var isOrgFirst = $("#isOrgFirst").val();
	var isShowBranch = $("#isShowBranch").val();
	var showType = $("#showType").val();
	$.ajax({
		url : getContextPath() + '/sys/org/list/getByParentId?queryTop=' + queryTop +
				"&isOrgFirst=" + isOrgFirst + "&isFirst=" + isFirst+"&isShowBranch=" +
				isShowBranch+"&showType=" + showType,
		type : "post",
	    dataType : "text",
	    success : function(data) {
	    	var zNodes = eval("(" + data + ")");
	    	ZtreeObj = $.fn.zTree.init($("#treeRegion"), setting, zNodes);
	    },
	    error : function(XMLHttpRequest, textStatus) {
	    	layer.msg(textStatus);
	    }
	});
});


function closed(){
	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引  
	parent.layer.close(index);//关闭弹出的子页面窗口
}

var layer;
layui.config({
	base: getContextPath() + '/static/layuiadmin/' //静态资源所在路径
}).extend({
	index: 'lib/index' //主入口模块
}).use(['layer'], function(){
	layer = layui.layer;
});
</script>
</body>
</html>